//
//  ImageViewController.m
//  Image
//
//  Created by zxs on 2017/6/1.
//  Copyright © 2017年 zxs. All rights reserved.
//

#import "ImageViewController.h"
#import "ImageTool.h"

@interface ImageViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (strong, nonatomic) UIImage *sampleImage;
@property (strong, nonatomic) UIImage *maskImage;

@end

@implementation ImageViewController

#pragma mark - life cycle

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.sampleImage = [UIImage imageNamed:@"sample"];
    self.maskImage = [UIImage imageNamed:@"mask"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - action
- (IBAction)waterTextButtonTouched:(UIButton *)sender {
    //设置字体样式
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    //NSFontAttributeName:字体大小
    dict[NSFontAttributeName] = [UIFont systemFontOfSize:20];
    //字体前景色
    dict[NSForegroundColorAttributeName] = [UIColor blueColor];
    //字体背景色
    dict[NSBackgroundColorAttributeName] = [UIColor redColor];
    //字体阴影
    NSShadow * shadow = [[NSShadow alloc]init];
    //阴影偏移量
    shadow.shadowOffset = CGSizeMake(2, 2);
    //阴影颜色
    shadow.shadowColor = [UIColor greenColor];
    //高斯模糊
    shadow.shadowBlurRadius = 5;
    dict[NSShadowAttributeName] = shadow;
    //字体间距
    dict[NSKernAttributeName] = @10;
    self.imageView.image = [ImageTool waterWithImage:self.sampleImage text:@"这是文字水印" point:CGPointMake(10, 10) attributed:[dict copy]];
}

- (IBAction)waterMaskButtonTouched:(UIButton *)sender {
    self.imageView.image = [ImageTool waterWithImage:self.sampleImage mask:self.maskImage rect:CGRectMake(10, 10, 50, 50)];
}

- (IBAction)clipCircleButtonTouched:(UIButton *)sender {
    // 推荐的用法，没有拉伸，图片质量不降低
    self.imageView.image = [ImageTool clipCircleWithImage:self.sampleImage];
    // 先拉伸，在裁剪，可以保证圆形，不过图片质量会降低
//    self.imageView.image = [ImageTool clipCircleWithImage:[ImageTool compressImage:self.sampleImage toSize:CGSizeMake(100, 100)]];
}

- (IBAction)clipCircleWithBorderButtonTouched:(UIButton *)sender {
    self.imageView.image = [ImageTool clipCircleWithImage:self.sampleImage borderWidth:4 borderColor:[UIColor blueColor]];
}

- (IBAction)compressButtonTouched:(UIButton *)sender {
    self.imageView.image = [ImageTool compressImage:self.sampleImage toSize:CGSizeMake(200, 200)];
}

- (IBAction)originalButtonTouched:(UIButton *)sender {
    self.imageView.image = self.sampleImage;
}

- (IBAction)removeBorderButtonTouched:(UIButton *)sender {
    self.imageView.layer.borderColor = [UIColor clearColor].CGColor;
    self.imageView.layer.borderWidth = 0;
}

- (IBAction)addBorderButtonTouched:(id)sender {
    // 在imageView上加边框，在圆形裁剪的时候会出问题。矩形是可以的。看情况使用
    self.imageView.layer.borderColor = [UIColor redColor].CGColor;
    self.imageView.layer.borderWidth = 5;
}

@end
